package com.ny.controller;

import com.ny.entity.Result;
import com.ny.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DeviceController {
    @Autowired
    private DeviceService deviceService;
    //查询所有设备信息
    //http://localhost:8083/selectAllDevice
    @GetMapping("/selectAllDevice")
    public Result selectAllDevice(){
        return Result.success(deviceService.findAllDevices());
    }
    //根据设备名称查询设备信息
    //http://localhost:8083/findDeviceByid?device_id=1
    @GetMapping("/findDeviceByid")
    public Result findDeviceByid(Integer device_id){
        return Result.success(deviceService.findDeviceByid(device_id));
    }
    //根据设备id删除设备信息
    //http://localhost:8083/deleteDeviceById?device_id=1
    @DeleteMapping("/deleteDeviceById")
    public Result deleteDeviceById(Integer device_id) {
        int result = deviceService.deleteDeviceById(device_id);
        if (result > 0) {
            return Result.success("设备删除成功");
        } else {
            return Result.error("设备删除失败");
        }
    }
}
